/// Returns the size of T
///
/// # Examples
///
/// ```rust
/// use meth_tools::prelude::size_of;
/// assert_eq!(
///     size_of(&vec![1,2,3,4,5]),
///     24,
/// )
/// ```
// #[allow(unused)]
pub fn size_of<T>(_: &T) -> usize {
    std::mem::size_of::<T>()
}

/// Reads the memory of a pointer with size
///
/// # Examples
///
/// ```rust
/// use meth_tools::prelude::read_memory_to_vec;
/// let v = vec![1,2,3];
/// println!("inner context: {:X?}",
///     read_memory_to_vec(v.as_ptr(), v.capacity() * meth_tools::prelude::size_of(&i32::default)));
/// ```
/// gets "inner context: [1, 0, 0, 0, 2, 0, 0, 0, 3, 0, 0, 0]"
// #[allow(unused)]
pub fn read_memory_to_vec<T>(addr: *const T, size: usize) -> Vec<u8> {
    let byte_ptr = addr as *const u8;
    unsafe {
        let slice = std::slice::from_raw_parts(byte_ptr, size);
        slice.to_vec()
    }
}

/// Reads the memory of a pointer
///
/// # Examples
///
/// ```rust
/// use meth_tools::prelude::read_variable_to_vec;
/// let v = vec![1,2,3];
/// println!("outer context: {:X?}", read_variable_to_vec(&v));
/// ```
/// gets "outer context: [3, 0, 0, 0, 0, 0, 0, 0, FF, FF, FF, FF, FF, FF, FF, FF, 3, 0, 0, 0, 0, 0, 0, 0]"
// #[allow(unused)]
pub fn read_variable_to_vec<T>(var: &T) -> Vec<u8> {
    let addr = var as *const T;
    let size = crate::prelude::size_of(var);
    read_memory_to_vec(addr, size)
}
